package Login;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class ModePane extends JPanel implements ActionListener, MouseListener, MouseMotionListener{
	private CardLayout cards;
	private int curFrame;
	private JPanel parent;
	private Button ceo, bk, mngr, back;
	private BufferedImage cm;
	private Timer time;
	private JFrame frame;
	
	public ModePane(JPanel parent, int n, CardLayout cards, JFrame frame){
		this.frame=frame;
		this.cards=cards;
		this.curFrame=n;
		this.parent=parent;
		
		try {
			ceo = new Button("images/2.png", "images/2a.png", "images/1.png");
			bk =  new Button("images/3.png", "images/3a.png", "images/1.png");
			mngr =  new Button("images/4.png", "images/4a.png", "images/1.png");
			back =  new Button("images/back.png", "images/back2.png", "images/back2a.png");
			
			cm= ImageIO.read(new File("images/cm.png"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.print("Image not found");
			e.printStackTrace();
		}
		
		time = new Timer(300, this);
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		repaint();
		
	}
	
	public void paint(Graphics g){
		super.paint(g);
		Graphics2D g2D = (Graphics2D) g;
		time.start();	
		g2D.drawImage(cm, 140, 90, null);
		
		g2D.drawImage(back.getCurImg(), 10, 10, null);
		
		
		if(ceo.getCurImgIndex()==0||ceo.getCurImgIndex()==2)
			g2D.drawImage(ceo.getCurImg(), 200, 150, null);
		if(ceo.getCurImgIndex()==1)
			g2D.drawImage(ceo.getCurImg(), 190, 150, null);
				
		if(bk.getCurImgIndex()==0||bk.getCurImgIndex()==2)
			g2D.drawImage(bk.getCurImg(), 50, 150, null);
		if(bk.getCurImgIndex()==1)
			g2D.drawImage(bk.getCurImg(), 40, 150, null);
			
		if(mngr.getCurImgIndex()==0||mngr.getCurImgIndex()==2)
			g2D.drawImage(mngr.getCurImg(), 350, 150, null);

		if(mngr.getCurImgIndex()==1)
			g2D.drawImage(mngr.getCurImg(), 340, 150, null);
		
		
				
	}
	
	@Override
	public void mouseClicked(MouseEvent m) {
		// TODO Auto-generated method stub
		LoginPane loginPane;
		if (m.getX() >= 54&& m.getX()<=137&&m.getY()>=150&&m.getY()<=346){//within the boundaries of bk
			loginPane = new LoginPane(parent, 3, cards, "images/loginb.png", frame);
			parent.add(loginPane, "3"); 
			cards.show(parent, curFrame+1+"");
			bk.setCurImg(0);
		}
	
		else if (m.getX() >= 204&& m.getX()<=284&&m.getY()>=151&&m.getY()<=333){//within the boundaries of ceo
			loginPane = new LoginPane(parent, 4, cards, "images/logina.png", frame);
			parent.add(loginPane, "4"); 
			cards.show(parent, curFrame+2+"");
			ceo.setCurImg(0);
		}
		else if (m.getX() >= 348&& m.getX()<=435&&m.getY()>=152&&m.getY()<=332){//within the boundaries of mngr
			loginPane = new LoginPane(parent, 5, cards, "images/loginc.png", frame);
			parent.add(loginPane, "5"); 
			cards.show(parent, curFrame+3+"");
			mngr.setCurImg(0);
		}
		else if (m.getX() >= 12&& m.getX()<=102&&m.getY()>=11&&m.getY()<=42){//within the boundaries of back
			cards.show(parent, curFrame-1+"");
			back.setCurImg(0);
		}
		
	}
	@Override
	public void mouseEntered(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent m) {
		// TODO Auto-generated method stub
		/*
		bk.setCurImg(2);
		ceo.setCurImg(2);
		mngr.setCurImg(2);
		back.setCurImg(2);
		*/
	}
	@Override
	public void mousePressed(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseDragged(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseMoved(MouseEvent m) {
		// TODO Auto-generated method stub
		if (m.getX() >= 54&& m.getX()<=137&&m.getY()>=150&&m.getY()<=346){//within the boundaries of bk
			bk.setCurImg(1);
		}
		else if (m.getX() >= 204&& m.getX()<=284&&m.getY()>=151&&m.getY()<=333){//within the boundaries of ceo
			ceo.setCurImg(1);
		}
		else if (m.getX() >= 348&& m.getX()<=435&&m.getY()>=152&&m.getY()<=332){//within the boundaries of mngr
			mngr.setCurImg(1);
		}
		else if (m.getX() >= 12&& m.getX()<=102&&m.getY()>=11&&m.getY()<=42){//within the boundaries of back
			back.setCurImg(1);
		}
		else{
			bk.setCurImg(0);
			ceo.setCurImg(0);
			mngr.setCurImg(0);
			back.setCurImg(0);
			
		}
		
		
	}
	

}
